import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_cost/app/config/custom_theme_data.dart';
import 'package:flutter_cost/app/config/route_config.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';

void main() async {
  await GetStorage.init();

  runApp(const MyApp());
  // 透明状态栏
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle =
        const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
      headerBuilder: () => const WaterDropHeader(waterDropColor: Colors.blue),
      enableScrollWhenRefreshCompleted: true,
      hideFooterWhenNotFull: true,
      child: GetMaterialApp(
        initialRoute: RouteConfig.index,
        getPages: RouteConfig.getPages,
        title: "记账cost",
        themeMode: ThemeMode.system,
        theme: ThemeData(
          useMaterial3: true,
          scaffoldBackgroundColor: const Color(0xFFF5F5F5),
          cardTheme: const CardTheme(color: Colors.white, elevation: 0),
          appBarTheme: const AppBarTheme(
            titleTextStyle: TextStyle(color: Color(0xFF333333), fontSize: 18),
            backgroundColor: Colors.white,
            centerTitle: true,
            elevation: 0,
          ),
          colorScheme: lightColorScheme,
        ),
        darkTheme: ThemeData(
          useMaterial3: true,
          scaffoldBackgroundColor: const Color(0xFF111111),
          cardTheme: const CardTheme(color: Color(0xFF191919), elevation: 0),
          appBarTheme: const AppBarTheme(
            titleTextStyle: TextStyle(color: Colors.white, fontSize: 18),
            backgroundColor: Color(0xFF111111),
            centerTitle: true,
            elevation: 0,
          ),
          colorScheme: darkColorScheme,
        ),
        navigatorObservers: [FlutterSmartDialog.observer],
        builder: FlutterSmartDialog.init(builder: _builder),
      ),
    );
  }
}

Widget _builder(BuildContext context, Widget? child) {
  return MediaQuery(
    ///设置字体不随系统字体变化
    data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
    child: child!,
  );
}
